package testSom;

import java.math.BigInteger;
import java.util.stream.LongStream;

public class TestParam {

    public static void main(String[] args) {
        long before = System.currentTimeMillis();
        long count = pi(100000000L);
        System.out.println(count);
        long after = System.currentTimeMillis();
        System.out.println(after - before);
        count = piParallel(100000000L);
        System.out.println(count);
        long after2 = System.currentTimeMillis();
        System.out.println(after2-after);
    }

    private static long pi(long n) {
        return LongStream.rangeClosed(2L, n)
                .mapToObj(BigInteger::valueOf)
                .filter(i -> i.isProbablePrime(50))
                .count();
    }

    private static long piParallel(long n) {
        return LongStream.rangeClosed(2L, n)
                .parallel()
                .mapToObj(BigInteger::valueOf)
                .filter(i -> i.isProbablePrime(50))
                .count();
    }

}
